$.ajaxSetup({
    //发送请求前 统一把token设置到header中
    beforeSend: async function (xhr, settings) { //可以设置自定义标头
        xhr.setRequestHeader('token', JSON.parse(localStorage.getItem('vuex')).token);
        settings.url = localStorage.getItem("baseURL") + settings.url;
    },
    //响应的统一处理 403 跳转到登录页
    complete: function (XMLHttpRequest, textStatus) {
        if (XMLHttpRequest.responseJSON.respCode === 403) {
            localStorage.removeItem('vuex')
            window.top.href = window.location.origin + '/#/login';
        }
    },
    error: function (xhr) {
        showWarnDialog('请求出现错误');
    }
});
function formSubmit(form, fileName) {
    form.onsubmit = function(e){
        e.preventDefault();
        var xhr = new XMLHttpRequest();
        xhr.open('POST', form.action, true);
        xhr.setRequestHeader('token', JSON.parse(localStorage.getItem('vuex')).token);
        xhr.responseType = 'blob';//设置ajax的响应类型为blob
        // xhr.withCredentials = true;
        xhr.onload = function () {
            if (this.status == 200) {
                var blob = this.response;//获取响应返回的blob对象
                if (typeof window.navigator.msSaveBlob !== 'undefined') {//否是IE浏览器
                    window.navigator.msSaveBlob(blob, fileName + ".xls");
                    return;
                }
                var a = document.createElement('a');
                a.href = window.URL.createObjectURL(blob);
                a.download = fileName + '.xls';
                a.click();
            } else {
                alert("下载失败");
            }
        }
        xhr.send(new FormData(form));
        // return false;
    };
}